

// let states=menus2;
let states=[
    {"id":1,"name":"航线历史收益统计","url":"/airline","type":1},
    {"id":2,"name":"机场历史运营","url":"/outPort","type":1},
    {"id":3,"name":"共飞运营对比","url":"/totalFlyAnalysis","type":1},
    {"id":4,"name":"客源组成","url":"/SourceDistribution","type":1},
    {"id":5,"name":"销售动态","url":"/buyTicketReport","type":1},
    {"id":6,"name":"航班动态","url":"/airline_dynamic","type":1},
    {"id":7,"name":"时刻查询","url":"/processTask","type":1},
    {"id":8,"name":"销售数据","type":1},
    {"id":9,"name":"关注航班配置","type":0},
    {"id":10,"name":"成员管理","type":1},
    {"id":11,"name":"角色管理","type":1},
    {"id":12,"name":"采集号配置信息","type":1},
    {"id":13,"name":"销售报表","type":1},
    {"id":14,"name":"航班异常原因编辑","type":1},
    {"id":15,"name":"自定义航班","type":0},
    {"id":16,"name":"默认","type":0}
    ];
let mapData = {
    "title": {
        "show": false,
        "left": "center",
        "textStyle": {"color": "#fff"}
    },
    "bmap": {
        "center": ["110.47", "32.40"],
        "zoom": 6,
        "color": "red",
        "roam": "move",
        "mapStyle": {
            "styleJson": [
                {
                    "featureType": "water",
                    "elementType": "all",
                    "stylers": {
                        "color": "#071327",
                        "visibility": "on"
                    }
                },
                {
                    "featureType": "land",
                    "elementType": "all",
                    "stylers": {
                        "color": "#223350",
                        "visibility": "on"
                    }
                },
                {
                    "featureType": "boundary",
                    "elementType": "all",
                    "stylers": {
                        "color": "#465b6c",
                        "visibility": "on"
                    }
                },
                {
                    "featureType": "arterial",
                    "elementType": "all",
                    "stylers": {
                        "visibility": "off"
                    }
                }, {
                    "featureType": "highway",
                    "elementType": "all",
                    "stylers": {
                        "visibility": "off"
                    }
                }, {
                    "featureType": "label",
                    "elementType": "all",
                    "stylers": {
                        "visibility": "off"
                    }
                }]
        },
        "scaleLimit": {"min": 5, "max": 10}
    },
    "tooltip": {
        trigger: 'item'
    },
    "series": [
        {
            "coordinateSystem": "bmap",
            "name":"所有航线",
            "type": "lines",
            "zlevel": 0,
            "effect": {
                "show": true,
                "period": 10,
                "trailLength": 0,
                "symbol": "path://M1705.06,1318.313v-89.254l-319.9-221.799l0.073-208.063c0.521-84.662-…5.125,42.917l0.531-42.034l-134.449-92.931l12.238-241.308L1705.06,1318.313z",
                "color": "#7fbce9",
                "symbolSize": 8
            },
            "lineStyle": {
                "normal": {
                    "color": "#4cc5f7",
                    "width": 0.8,
                    "opacity": 0.4,
                    "curveness": 0.2
                },
                "emphasis": {
                    "color": "#3887be"
                }
            },
            "polyline": false,
            "data": []
        },
        {
            "type": "scatter",
            "name":"核心机场",
            "coordinateSystem": "bmap",
            "data": '',
            "zlevel": 10,
            "symbolSize": [15, 20],
            "symbol": "path://M786.496 161.163l-3.537-3.507C713.308 88.89 617.627 46.381 511.992 46.381c-105.507 0-201.123 42.418-270.76 111.073l-3.926 3.911c-68.646 69.668-111.074 165.237-111.074 270.775 0 105.633 42.495 201.295 111.275 270.965l3.522 3.508 270.978 271.006 271.169-271.146 3.132-3.164c68.889-69.697 111.459-165.424 111.459-271.164C897.772 326.521 855.277 230.86 786.496 161.163L786.496 161.163zM512.008 541.766c-74.545 0-134.974-60.447-134.974-134.977 0-30.806 10.283-59.152 27.614-81.856 24.663-32.299 63.574-53.151 107.359-53.151 74.55 0 134.978 60.463 134.978 135.008C646.985 481.318 586.558 541.766 512.008 541.766L512.008 541.766zM512.008 541.766",
            "symbolOffset": [0, -8],
            "itemStyle": {
                "emphasis": {},
                "normal": {
                    "color": "#d85230"
                }
            }
        },
        {
            "type": "scatter",
            "name":"全国重点机场",
            "coordinateSystem": "bmap",
            "symbol": "circle",
            "symbolSize": 5,
            "zlevel": 10,
            "label": {
                "normal": {
                    "show": true,
                    "position": "right",
                    "formatter": "{b}"
                },
                "emphasis": {
                    "show": true
                }
            },
            "itemStyle": {
                "normal": {"color": "#7fbce9"}
            },
            "data": [
            ]
        }
    ]
};
let permissions=states;
let menuc={
    ariList:[],
    head:{
        url:'',
        text:'',
        CNtext: ''
    }
};
let sionName = window.sessionStorage.getItem('groupName');
$.ajax({
    url:'/getPortalData',
    type:'post',
    dataType:'json',
    success:(data)=>{
        // 柱状图 ["#7ebbe8","#fcc572","#52b678","#7390b5","#e19595","#a4b0c0","#047434","#2f5688","#d2881d","#e45c4d"]
        // 饼状图["#7ebbe8","#2f5688","#d3a156","#eec494","#93a0b2","#c9877f","#cecfd1","#5871e2","#2761d2","#4526d2"]
        state.portalData=data;
        //改为登录用户名
        menuc.head.text=data.userName;
        menuc.head.CNtext=data.groupName;
        menuc.ariList=data.groupName;
        let line_arr=[];
        let sca_arr=[];
        let name_arr=[];
        let dian_arr=[];
        let all_line = {};
        let forDianClear = [];
        for(let key in data.list){
            if(data.list[key].airlines && data.list[key].airlines.length>0 && data.airportInfoMap[key]){
                if(forDianClear.indexOf(data.airportInfoMap[key].ctyChaNam)<0){
                    forDianClear.push(data.airportInfoMap[key].iata);
                    dian_arr.push({
                        "name": data.airportInfoMap[key].ctyChaNam,
                        "typeScatter":1,
                        "code":data.airportInfoMap[key].iata,
                        "value": [data.airportInfoMap[key].coordinate.split(",")[0], data.airportInfoMap[key].coordinate.split(",")[1], 100],
                        "label": {
                            "normal": {
                                "show": true,
                                "position": "right",
                                "formatter": data.airportInfoMap[key].iata,
                                "textStyle": {
                                    "color": "white",
                                    "fontSize": 12
                                },
                                "itemStyle": {}
                            },
                            "emphasis": {
                                "show": false
                            }
                        },
                        "tooltip":{
                            "show":false
                        }
                    });
                }
                name_arr.push({  //添加机场列表信息
                    "name":data.airportInfoMap[key].aptChaNam,
                    "code":key,
                    "oname":data.airportInfoMap[key].ctyChaNam
                });
                let li_line = [];
                for(let i=0;i<data.list[key].airlines.length;i++){
                    line_arr.push(  {
                        "fromName": data.list[key].airlines[i].fromName,
                        "toName": data.list[key].airlines[i].toName,
                        "coords": [data.list[key].airlines[i].coords.fromName, data.list[key].airlines[i].coords.toName]
                    });
                    li_line.push(  {
                        "fromName": data.list[key].airlines[i].fromName,
                        "toName": data.list[key].airlines[i].toName,
                        "coords": [data.list[key].airlines[i].coords.fromName, data.list[key].airlines[i].coords.toName]
                    });
                    sca_arr.push({
                        name:data.list[key].airlines[i].toName,
                        typeScatter:0,
                        value:[data.list[key].airlines[i].coords.toName[0],data.list[key].airlines[i].coords.toName[1],30],
                        tooltip:{
                            show:false
                        }
                    });
                    sca_arr.push({
                        name:data.list[key].airlines[i].fromName,
                        typeScatter:0,
                        value:[data.list[key].airlines[i].coords.fromName[0],data.list[key].airlines[i].coords.fromName[1],30],
                        tooltip:{
                            show:false
                        }
                    })
                }
                all_line[key] = li_line;
            }
        };
        let ret = [];
        for (let i = 0; i<sca_arr.length; i++) {
            let tn=true;
            for(let j = 0; j<ret.length; j++){
                if(ret[j].name==sca_arr[i].name){
                    tn=false;
                }
            }
            for(let j = 0; j<name_arr.length; j++){
                sca_arr[i].name
                if(name_arr[j].oname==sca_arr[i].name){
                    tn=false;
                }
            }
            if(tn){
                ret.push(sca_arr[i]);
            }
        }
        mapData.series[0].data = line_arr;
        mapData.series[1].data = dian_arr;
        mapData.series[2].data = ret;
        let ssionName = window.sessionStorage.getItem('groupName');
        if(!ssionName){
            ssionName = data.groupName;
            window.sessionStorage.setItem('groupName',data.groupName);
            window.sessionStorage.setItem('nameList',JSON.stringify(name_arr));
        }
        menuc.head.CNtext = ssionName;
        menuc.ariList = name_arr;
        state.mapDataOld = JSON.parse(JSON.stringify(mapData));
        state.mapData = JSON.parse(JSON.stringify(mapData));
        state.menuc = JSON.parse(JSON.stringify(menuc));
        state.all_line = all_line;
    }
});
export const state={
    permissions:permissions,
    mapState:0,
    mapDataOld:"",
    mapAllline:"",
    mapData:mapData,
    menuc:menuc,
    portalData:'',
    nested_page:false,
    c_updated:false,    //控制菜单关闭按钮 -需在watch里监听这个数据变化
    all_line:null
};
